unit Unit51; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, sqldb, db,
  DbCtrls, StdCtrls, Unit1;

type

  { TForm51 }

  TForm51 = class(TForm)
    Datasource1: TDatasource;
    DBComboBox1: TDBComboBox;
    Label1: TLabel;
    SQLQuery1: TSQLQuery;
    procedure DBComboBox1Select(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    funcionario : string;
  end; 

var
  Form51: TForm51; 

implementation

{ TForm51 }

procedure TForm51.FormCreate(Sender: TObject);
begin
  SQLQuery1.DataBase := Form1.PQConnection1;
  SQLQuery1.Transaction := Form1.SQLTransaction1;
end;

procedure TForm51.DBComboBox1Select(Sender: TObject);
begin
  funcionario := DBComboBox1.Text;
  Close;
end;

procedure TForm51.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  if SQLQuery1.Active = true then
    SQLQuery1.Close;
end;

procedure TForm51.FormShow(Sender: TObject);
begin
  if SQLQuery1.Active = true then
    SQLQuery1.Close;
    
  SQLQuery1.SQL.Text := 'select fnc_nombre from funcionario';

  SQLQuery1.Open;

  DBComboBox1.DataField := 'fnc_nombre';
  DBComboBox1.Clear;

  while not SQLQuery1.EOF do
  begin
    DBComboBox1.Items.Add(SQLQuery1.Fields[0].AsString);
    SQLQuery1.Next;
  end;

  DBComboBox1.Text := '';
end;

initialization
  {$I unit51.lrs}

end.

